﻿using Styx;
using Styx.CommonBot.Routines;
using Styx.Helpers;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Styx.TreeSharp;
using Action = Styx.TreeSharp.Action;

using CommonBehaviors.Actions;
using System.Collections.Generic;


namespace Crusader
{
    partial class Routine : CombatRoutine
    {

        partial class Paladin
        {

            #region Statics


            #endregion

            #region Combat composites

            public static Composite HolyCombatBehavior()
            {

                return new Decorator(ret => Me.CurrentTarget != null && !Me.Mounted,
                    new PrioritySelector(
                        
                        BestHealTarget(),

                        new Decorator(ret => !Me.IsCasting,
                            new PrioritySelector(
                                CastSpell("Holy Shock"),
                                CastSpell("Flash of Light", ret=> Me.CurrentTarget.HealthPercent < 40),
                                CastSpell("Word of Glory", ret=> Me.CurrentTarget.HealthPercent < 60 && Me.CurrentHolyPower > 2),
                                CastSpell("Divine Light", ret => Me.CurrentTarget.HealthPercent < 60),
                                CastSpell("Holy Light", ret => Me.CurrentTarget.HealthPercent < 80)
                            )
                        )
                    )
                );
            }

            public static Composite BestHealTarget()
            {
                return new Action(delegate {
                    IEnumerable<WoWUnit> f = NearbyFriendlyUnits;

                    WoWUnit t = Me;

                    foreach (WoWUnit u in NearbyFriendlyUnits)
                    {
                        if (u.HealthPercent < t.HealthPercent)
                            t = u;
                    }
                    if (t.HealthPercent < 80)
                        t.Target();
                    else
                        Me.ClearTarget();
                });
            }

            #endregion
        }
    }
}
